﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_FlowForm.cshtml";
}@using LeSoft.Application.Code;
<script src="~/Content/scripts/jquery/layer/jquery.js?v=1.83.min"></script>
<script src="~/Content/scripts/jquery/layer/layer.min.js"></script>
<link href="~/Content/styles/font-awesome.min.css" rel="stylesheet" />
<link href="~/Content/styles/BillDetail.css?v=1.1" rel="stylesheet" />
<link href="~/Content/styles/anitmate.css" rel="stylesheet" />
<link href="~/Content/styles/style.css" rel="stylesheet" />
<link href="~/Content/scripts/plugins/tree/tree.css" rel="stylesheet" />
<link href="~/Content/scripts/plugins/jqgrid/jqgrid.css" rel="stylesheet" />
<script src="~/Content/scripts/plugins/tree/tree.js"></script>
<script src="/Content/scripts/plugins/validator/js?v=XgpF3bkqcHESsLip2j1dhS6n2I-zHyD2VCazpanqH6Q1"></script>
<script src="/Content/scripts/utils/js?v=FNqaC7G7A87_J4VCIQpQEAO-d_2Qf2wSxoZexwRzulo1"></script>
<script src="~/Content/scripts/plugins/jqgrid/jqgrid.js"></script>
<script src="~/Content/scripts/jquery/ajaxfileupload.js"></script>
<script src="~/Content/scripts/utils/LeSoft-ui.js"></script>
<script>
    var keyValue = request('keyValue');
    $(function () {
        initControl();
        GetFeeGrid("");

    });

    function initControl() {

        $("#OrganzieId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJson",
            description: "==请选择所属机构==",
            height: "250px",
            click: function (data) {
                organizeid = data.id;
            }
        });
        //发票类型
        $("#InvoiceType").ComboBoxTree({
            url: "../../SystemManage/DataItemDetail/GetDataItemTreeJson?Encode=InvoiceType",
            description: "==请选择==",
            height: "150px"
        });
        //收款方式
        $("#PayWay").ComboBoxTree({
            url: "../../SystemManage/DataItemDetail/GetDataItemTreeJson?Encode=PayWay",
            description: "==请选择==",
            height: "150px"
        });
        if (!!keyValue) {
            $.SetForm({
                url: "../../FinancialManage/ReceiptBill/GetReceiptBillInfo",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data.BillInfo);
                    GetOperateGrid(data.BillInfo.OperateMemo);
                    $("#CustomerName").val(data.CustomerInfo.Name + "(" + data.CustomerInfo.Code + ")");
                    $("#Adderr").val(data.PStructInfo.AllName);
                    GetFeeGrid(data.list);
                }

            });
        }


    }

    //费用列表
    function GetFeeGrid(data) {
        $gridTable = $("#gridTable_Fee");
        var selectedRowIndex = 0;
        var lastsel;
        function my_input1(value, options) {
            return $("<input type='number' onkeyup='Binding();' class='editable center'  value='" + value + "'/>");
        }
        function my_value(value) {
            return "My value: " + value.val();
        }
        $gridTable.jqGrid({
            datatype: "json",
            autowidth: true,
            height: 400,
            colModel: [
                { label: "主键", name: "id", hidden: true },
                { label: "费项名称", name: "name", index: "name", width: 180, align: "center", sortable: false },
                { label: "应收年月", name: "receivemonth", index: "receivemonth", width: 150, align: "center", sortable: false },
                { label: "计费起始日期", name: "begindate", index: "begindate", width: 150, align: "center", sortable: false },
                { label: "计费终止日期", name: "enddate", index: "enddate", width: 150, align: "center", sortable: false },
                { label: "应收金额", name: "receiveamount", index: "receiveamount", width: 120, align: "center", sortable: false },
                { label: "已收金额", name: "receivedamount", index: "receivedamount", width: 120, align: "center", sortable: false },
                { label: "未收金额", name: "memo", index: "memo", width: 120, align: "center", sortable: false },
                {
                    label: "本次收款", name: "amount", index: "amount", width: 180, align: "center", sortable: false, editable: true,
                    edittype: 'custom', editoptions: { custom_element: my_input1, custom_value: my_value, }
                },
                { label: "附加说明", name: "description", index: "description", width: 300, align: "center", sortable: false },
            ],
            viewrecords: true,
            rowNum: 1000,
            rownumbers: true,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                $gridTable.editRow(status, {
                    keys: true, successfunc: function (response) {
                        $gridTable.jqGrid('saveRow', lastsel);
                        return true;
                    }
                })
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
        });
        $gridTable[0].addJSONData(data);

    }
    //操作记录
    function GetOperateGrid(data) {
        $gridTable = $("#gridTable_Operate");
        $gridTable.jqGrid({
            datatype: "json",
            height: 650,
            hidegrid: false,
            caption: "操作记录",
            autowidth: true,
            colModel: [
               { label: '项目主键', name: 'Id', hidden: true },
                        { label: '业务类别', name: 'Type', width: 100, align: 'center', sortable: false },
                        { label: '操作人', name: 'FormOperateName', width: 100, align: 'center', sortable: false },
                        { label: '操作时间', name: 'Date', width: 170, align: 'center', sortable: false },
                        {
                            label: "操作内容", name: "Content", index: "Content", width: 590, align: "left", sortable: false,
                            formatter: function (cellvalue, options, rowObject) {
                                if (!!rowObject.ToOperateName)
                                    return "发起者：" + rowObject.FormOperateName + "，接受者：" + rowObject.ToOperateName + "<br/>" + cellvalue;
                                else
                                    return "发起者：" + rowObject.FormOperateName + "<br/>" + cellvalue;
                            }
                        },
            ],
            viewrecords: true,
            rownumbers: true,

        });
        $gridTable[0].addJSONData(JSON.parse("[" + data + "]"));


    }
    function Binding() {
        debugger;
        var $gridTable = $('#gridTable_Fee');
        var count = $gridTable.getGridParam("records");
        var TotalAmount = 0.00;
        var id = $gridTable.getDataIDs();
        for (var i = 0; i < count; i++) {
            debugger;
            var Amount = parseFloat($("#" + id[i] + "_amount").val());
            if (isNaN(Amount)) {
                Amount = parseFloat($gridTable.getCell(id[i], "amount"));
                TotalAmount += Amount;
            }
            else {
                Amount = parseFloat($("#" + id[i] + "_amount").val());
                TotalAmount += Amount;
            }
        }
        $("#PayAmount").val(parseInt(TotalAmount));
    }

    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var Lst = [];

        var $gridTable = $('#gridTable_Fee');
        var obj = $gridTable.jqGrid("getRowData");
        for (var i = 0; i < obj.length; i++) {
            var Amount = parseFloat($("#" + obj[i].id + "_amount").val());
            if (isNaN(Amount)) {
                Amount = parseFloat($gridTable.getCell(obj[i].id, "amount"));
            }
            if (isNaN(Amount)) {
                Amount = 0;
            }
            Lst.push({
                Id: obj[i].id,
                Amount: Amount
            })
        }
        var postData = $("#form1").GetWebControls(keyValue);
        $.ConfirmAjax({
            msg: "注：您确认要保存此操作吗？",
            url: "../../FinancialManage/ReceiptBill/SaveForm?keyValue=" + keyValue,
            param: { queryJson: JSON.stringify(postData), Lst: JSON.stringify(Lst) },
            success: function (data) {
                $.currentIframe().$("#gridTable").resetSelection();
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
                dialogClose();
            }
        });
    }
</script>
<style>
    .center {
        text-align: center;
    }
</style>
<div id="wrapper" style="background:#fff;">
    <div id="left-side" style="margin-top:5px;">
        <ul>
            <li class="choose active">
                单据信息
            </li>
            <li class="pay">
                业务日志
            </li>
        </ul>
    </div>
    <div id="border">
        <div id="line" class="one"></div>
    </div>
    <div id="right-side" class="tab-content" style="width:100%;">
        <div id="first" class="tab-pane active">
            <div class="tab-content">
                <table class="form " style="width: 95%; ">
                    <tr>
                        <td class="formTitle">所属机构<font face="宋体">*</font></td>
                        <td class="formValue">
                            <div id="OrganzieId" type="selectTree" readonly class="ui-select "></div>
                        </td>
                        <th class="formTitle">单据编号<font face="宋体">*</font></th>
                        <td class="formValue">
                            <input id="Code" type="text" readonly class="form-control " />
                        </td>
                        <th class="formTitle">单据日期<font face="宋体">*</font></th>
                        <td class="formValue">
                            <input id="Date" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({maxDate:'%y-%M-%d'})">
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">客户名称<font face="宋体">*</font></th>
                        <td class="formValue">
                            <input id="CustomerName" readonly type="text" class="form-control " />
                        </td>
                        <th class="formTitle">房屋地址<font face="宋体">*</font></th>
                        <td class="formValue" colspan="3">
                            <input id="Adderr" type="text" readonly class="form-control" />
                        </td>
                    </tr>
                    <tr style="height:15px;"><td colspan="6" style="border-bottom:1px #ccc dashed;"></td> </tr>
                    <tr style="height:15px;"><td></td></tr>
                </table>
                <table class="form" id="form" style="width: 95%; ">
                    <tr>
                        <th class="formTitle">收款方式</th>
                        <td class="formValue">
                            <div id="PayWay" type="selectTree" class="ui-select BassClass"></div>
                        </td>
                        <th class="formTitle">实收金额</th>
                        <td class="formValue">
                            <input id="PayAmount" type="text" readonly class="form-control " />
                        </td>
                        <th class="formTitle">银行流水</th>
                        <td class="formValue">
                            <input id="PayBillNo" type="text" class="form-control " />
                        </td>
                    </tr>
                    <tr>

                        <th class="formTitle">票据类型</th>
                        <td class="formValue">
                            <div id="InvoiceType" type="selectTree" class="ui-select BassClass"></div>
                        </td>
                        <th class="formTitle">票据编号</th>
                        <td class="formValue">
                            <input id="InvoiceNo" type="text" class="form-control " />
                        </td>
                        <th class="formTitle">票据抬头</th>
                        <td class="formValue">
                            <input id="InvoiceTitle" type="text" class="form-control" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">附加说明</th>
                        <td class="formValue" colspan="5">
                            <textarea id="Description" class="form-control BaseClass" style="height: 50px;"></textarea>
                        </td>
                    </tr>
                    <tr style="height:15px;"><td colspan="6" style="border-bottom:1px #ccc dashed;"></td> </tr>
                    <tr style="height:15px;">
                    <tr>
                        <td colspan="6">
                            <div class="gridPanel">
                                <table id="gridTable_Fee"></table>
                            </div>
                        </td>
                    </tr>
                </table>

            </div>
        </div>
        <div id="second" class="tab-pane" style="max-height: 762px;overflow-y: scroll;">
            <table class="form" id="Repairform1">
                <tr>
                    <td>
                        <div class="gridPanel">
                            <table id="gridTable_Operate"></table>
                        </div>
                    </td>
                </tr>

            </table>
        </div>

    </div>
    <script>
        $('.choose').click(function () {
            $('.choose').addClass('active');
            $('.pay').removeClass('active');
            $('#line').addClass('one');
            $('#line').removeClass('two');
            $('#first').addClass('active');
            $('#second').removeClass('active');
            $("#right-side table").css("margin", "0px");

        });
        $('.pay').click(function () {
            $('.pay').addClass('active');
            $('.choose').removeClass('active');
            $('#line').addClass('two');
            $('#line').removeClass('one');
            $('#first').removeClass('active');
            $('#second').addClass('active');
            $("#right-side table").css("margin", "0px");
        });



    </script>

</div>

